package org.vectrics.recruiter.job.event;

import java.util.Locale;

import org.vectrics.common.html.BorderTable;
import org.vectrics.mail.EmailTable;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.job.Job;
import org.vectrics.recruiter.job.JobCandidate;

public class JobCandidateInfoEmailTable extends EmailTable {

	public JobCandidateInfoEmailTable(Locale locale, JobCandidate jobCandidate, boolean showCompany) {
		super(locale);
		this.setWidth(600);
		Job job = jobCandidate.getJob();
		this.addProperyRow( 
				this.getPhrase("prompt.candidate.name"), 
				jobCandidate.getCandidate().getPerson().getName());

		if (jobCandidate.getCurrentStatus() == null) {
			this.addProperyRow( 
					this.getPhrase("prompt.job.candidate.status"), 
					null);
		} else {
			this.addProperyRow( 
					this.getPhrase("prompt.job.candidate.status"), 
					jobCandidate.getCurrentStatus().getStatusType().getDescription());
		}

		String homePhone = null;
		String workPhone = null;
		String city = null;
		String state = null;
		if (jobCandidate.getCandidate().getPerson().getContactInfo() != null) {
			if (jobCandidate.getCandidate().getPerson().getContactInfo().getHomePhone() != null)
				homePhone = jobCandidate.getCandidate().getPerson().getContactInfo().getHomePhone().getFormattedNumber();
			if (jobCandidate.getCandidate().getPerson().getContactInfo().getWorkPhone() != null)
				workPhone = jobCandidate.getCandidate().getPerson().getContactInfo().getWorkPhone().getFormattedNumber();
			if (jobCandidate.getCandidate().getPerson().getContactInfo().getHomeAddress() != null) {
				city = jobCandidate.getCandidate().getPerson().getContactInfo().getHomeAddress().getCity();
				state = jobCandidate.getCandidate().getPerson().getContactInfo().getHomeAddress().getState();
			}
		}
		this.addProperyRow( 
				this.getPhrase("prompt.home.phone"), 
				homePhone);
		this.addProperyRow( 
				this.getPhrase("prompt.work.phone"), 
				workPhone);
		this.addProperyRow( 
				this.getPhrase("prompt.home.state"), 
				state);
		this.addProperyRow( 
				this.getPhrase("prompt.home.city"), 
				city);
		if (showCompany) {
			this.addProperyRow( 
					this.getPhrase("prompt.job.company"), 
					job.getCompany().getName() 
			);
		}
		
		this.addProperyRow( 
				this.getPhrase("prompt.job.candidate.date.created"), 
				CoreServiceLocator.getDateFormat().getDateFormatRoundToDay(this.getLocale()).format(jobCandidate.getDateAdded()) 
				);
	}

}
